#pragma once
#include <xpam/point.h>
#include <xpam/size.h>

namespace xpam
{
    template<class T1>
    class rectangle
    {
    private:
        T1 _x1, _y1, _x2, _y2;
    public:
        rectangle(T1 x1, T1 y1, T1 x2, T1 y2) : _x1(x1), _y1(y1), _x2(x2), _y2(y2) { }
        rectangle(const point<T1> & pt, const size<T1> & sz) : _x1(pt.x), _y1(pt.y), _x2(pt.x + sz.width), _y2(pt.y + sz.height) { }
    public:
        T1 left() const { return std::min<T1>(_x1, _x2); }
        T1 top() const { return std::min<T1>(_y1, _y2); }
        T1 right() const { return std::max<T1>(_x1, _x2); }
        T1 bottom() const { return std::max<T1>(_y1, _y2); }

        T1 x() const { return left(); }
        T1 y() const { return top(); }
        T1 width() const { return std::abs(_x1 - _x2); }
        T1 height() const { return std::abs(_y1 - _y2); }

        void top(T1 top) { _y2 = bottom(); _y1 = top; _y2 = bottom(); }

        point<T1> get_location() const { return point<T1>(x(), y()); }
        size<T1> get_size() const { return size<T1>(width(), height()); }

    };
}